/**
 * Copyright (C) 2021 - 2031 O-Cubes Co., Ltd.
 */

/****************************************************************
 *  @file    uart_dma_test.c
 *  @brief   UART dma testcase source file
 *  @version v1.0
 *  @date    03. Apr. 2023
 ****************************************************************/

#include "hal_api.h"
#include "printf.h"
#include "common.h"

#define DMA_TX_DMA_CHAN            0
#define DMA_RX_DMA_CHAN            1
#define BUF_LEN                    1024
#define UART_ID                    4

//static __align(64) uint8_t uart_dma_rbuf[BUF_LEN];
static __align(64) uint8_t uart_dma_wbuf[BUF_LEN];


int32_t test_uart_dma(void)
{
	int32_t ret;
	uint32_t i;
	printf("\r\n[UART DMA]: TEST START\r\n");
	ret = Hal_Uart_Request_Dma_Chan(UART_ID, DMA_TX_DMA_CHAN, DMA_RX_DMA_CHAN);
	if (ret) {
		printf("[UART DMA]: requeset dma channel failed\r\n");
		return ret;
	}
	for (i = 0; i < BUF_LEN; i++) {
		uart_dma_wbuf[i] = i % 256;
	}
	Hal_Uart_Dma_Write(0, uart_dma_wbuf, BUF_LEN);
	/*
	Hal_Uart_Dma_Read(0, uart_dma_rbuf, BUF_LEN);
	for(i = 0; i < BUF_LEN; i++) {
		printf("[UART DMA]: the read data is %d\n", uart_dma_wbuf[i]);
	}
	*/
	printf("\r\n[UART DMA]: TEST END\r\n");

	return 0;
}

